home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / N-P / OOP for C.cpt / Flavors4C.ƒ / Flavor4C.h next >
Text File  |  1988-11-30  |  10KB  |  371 lines

  1. /****************************************************************************/
  2. /*         Flavors4C, an object oriented library in C, Version 1.0          */
  3. /*            © Copyright 1988 Peter Ohler,  All Rights Reserved            */
  4. /*  460 Monti Court                                                         */
  5. /*  Pleasant Hill, CA  94523                                                */
  6. /*  (415) 686-1317                                                          */
  7. /****************************************************************************/
  8. /* flavor4c.h                                                               */
  9. /*--------------------------------------------------------------------------*/
  10.  
  11. /*  CFlavors is an object oriented package for C.  It should work on any
  12.     C compiler that supports the K&R C standard.  It is not a preprocessor
  13.     but consists of the library cflavors and the header file cflavors.h.
  14.     Some standard libraries and headers are needed to allow memory
  15.     allocation and IO.  (It calls malloc(), sprintf() and printf()).
  16.     
  17.     CFlavors does not adhere rigidly to the flavors found on LISP machines
  18.     since, after all this is C not LISP.  It does, however, encompass most
  19.     of the concepts that LISP flavors includes and when ever possible syntax
  20.     is similar.  Users familiar with LISP flavors will notice many
  21.     similarities between CFlavors and LISP flavors.  This similarity should
  22.     allow an easy translation from LISP to C.
  23. */
  24.  
  25.  
  26. /*  These defines are used to keep function and variable names readable yet
  27.     smaller than 8 characters for some compilers.
  28. */
  29. #define allFlavors          allFlavs
  30. #define WarningFunction     cf_warn
  31. #define error_check         error_ck
  32. #define flavor_specifier    flav_spc
  33.  
  34. #define DefFlavor           DefFlav
  35. #define AbstractFlavor      AbstFlav
  36. #define RequiredVars        ReqVars
  37. #define RequiredMethods     ReqMeths
  38. #define RequiredFlavors     ReqFlavs
  39. #define IncludedFlavors     IncFlavs
  40. #define NoVanillaFlavor     NoVanil
  41. #define MethodCombination   MethComb
  42. #define DefaultHandler      DefHand
  43. #define DefMethod           DefMeth
  44. #define CompileFlavor       CompFlav
  45. #define ContinueWhopper     ContWhop
  46. #define StringToFlavor      StrTFlav
  47. #define FlavorToString      FlavTStr
  48. #define MakeInstance        MakeInst
  49. #define BroadCast           BroadCst
  50.  
  51.  
  52. /*  These are the public types.  It is left up to the user to keep track of
  53.     each structure.
  54. */
  55. typedef struct flavor       Flavor;
  56. typedef struct instance        Instance;
  57.  
  58. typedef char    *Pntr;
  59.  
  60. /*
  61.     allFlavors is a NULL terminated array of all the defined flavors.
  62. */
  63. extern Flavor   **allFlavors;
  64.  
  65. /*
  66.     WarningFunction is a pointer to the function used to display warning
  67.     messages.  It can be reset to point to some user defined function at the
  68.     user's discretion.  It takes a single argument which is a string.
  69. */
  70. extern int      (*WarningFunction)();
  71.  
  72. /*
  73.     error_check is a flag which enables the error checking during execution.
  74.     Once the code is tested some performance improvement can be realized by
  75.     setting it to 0 and disabling some of the error checks.
  76. */
  77. extern int      error_check;
  78.  
  79. /*
  80.     flavor_specifier is a flag used to indicate how CFlavors reads flavor
  81.     arguments in many functions.
  82. */
  83. extern int      flavor_specifier;
  84.  
  85.  
  86. #define STR_SPECIFY      0x01
  87. #define Pntr_SPECIFY     0x02
  88.  
  89. extern int  flavor_specifier;   /* default is (STR_SPECIFY | Pntr_SPECIFY) */
  90.  
  91. #define NOT_DEFINED     0x00
  92. #define DAEMON          0x01
  93. #define OR_COMB         0x02
  94. #define AND_COMB        0x03
  95. #define DAEMON_OR       0x04
  96. #define DAEMON_AND      0x05
  97. #define PROGN           0x06
  98.  
  99. #define BASE_FLAVOR_LAST    0x00
  100. #define BASE_FLAVOR_FIRST   0x10
  101.  
  102. #define PRIMARY 0x01
  103. #define BEFORE  0x02
  104. #define AFTER   0x04
  105. #define AROUND  WHOPPER
  106. #define WHOPPER 0x08
  107.  
  108. #define GETTABLE    0x01
  109. #define SETTABLE    0x02
  110. #define ALL         0xFF
  111.  
  112. #define INIT        NULL
  113. #define NO_INIT     0x01
  114.  
  115.  
  116. /*
  117. Flavor*
  118. DefFlavor(name, parents)
  119.     char    *name;
  120.     Pntr    parents;
  121.  
  122.     DefFlavor is used to define or create a Flavor (Class).  After the basic
  123.     Flavor has been created the Variables, and  Methods can be added to it.
  124.     The first argument to DefFlavor is a string and the second argument
  125.     (parents) is a NULL terminated array of the parent flavors or a string 
  126.     composed of the the names of the parent flavors separated by white space.
  127. */
  128. extern Flavor  *DefFlavor();
  129.  
  130.  
  131. /*
  132. void
  133. AbstractFlavor(flavor)
  134.     Pntr    flavor;
  135.  
  136.     AbstractFlavor() indicates that the flavor will not be used to create an
  137.     instance.  The flavor can only be used as a mixin with other flavors.
  138.     An error occurs if an attempt is made to create an instance of this
  139.     flavor.
  140. */
  141. extern void AbstractFlavor();
  142.  
  143.  
  144. /*
  145. void
  146. RequiredVars(flavor, varNames)
  147.     Pntr    flavor;
  148.     char    *varNames;
  149.     
  150. */
  151. extern void RequiredVars();
  152.  
  153.  
  154. /*
  155. void
  156. RequiredMethods(flavor, methods)
  157.     Pntr    flavor;
  158.     char    *methods;
  159.     
  160. */
  161. extern void RequiredMethods();
  162.  
  163.  
  164. /*
  165. void
  166. RequiredFlavors(flavor, required)
  167.     Pntr    flavor;
  168.     Pntr    required;
  169.  
  170. */
  171. extern void RequiredFlavors();
  172.  
  173.  
  174. /*
  175. void
  176. IncludedFlavors(flavor, included)
  177.     Pntr    flavor;
  178.     Pntr    included;
  179.  
  180. */
  181. extern void IncludedFlavors();
  182.  
  183.  
  184. /*
  185. void
  186. NoVanillaFlavor(flavor)
  187.     Pntr    flavor;
  188.  
  189. */
  190. extern void NoVanillaFlavor();
  191.  
  192.  
  193. /*
  194. void
  195. MethodCombination(flavor, type, order, methods)
  196.     Pntr    flavor;
  197.     int     type, order;
  198.     char    *methods;
  199.  
  200. */
  201. extern void MethodCombination();
  202.  
  203.  
  204. /*
  205. void
  206. DefaultHandler(flavor, function)
  207.     Pntr    flavor;
  208.     Pntr    (*function)();
  209.  
  210. */
  211. extern void DefaultHandler();
  212.  
  213.  
  214. /*
  215. void
  216. DefMethod(flavor, type, name, function)
  217.     Pntr    flavor;
  218.     char    type, *name;
  219.     Pntr    (*function)();
  220.  
  221. */
  222. extern void DefMethod();
  223.  
  224.  
  225. /*
  226. Pntr
  227. AddInstanceVar(flavor, name, flags, type, initValue)
  228.     Pntr    flavor;
  229.     char    *name;
  230.     int     flags;
  231.     ....    type, initValue;
  232.  
  233.     AddInstanceVar() is used to add instance variables to a Flavor before
  234.     the flavor is compiled.  The flavor argument must be a pointer to a
  235.     flavor or a flavor name.  The name must be a string which is the name
  236.     of the variable.  The flags argument must be a logical OR
  237.     combination of GETTABLE, SETTABLE, or ALL.  The type and initValue
  238.     should match and can be any type that the compiler supports.
  239. */
  240. #define AddInstanceVar(flavor, name, flags, type, initValue) \
  241.   *((type*)addIVar(flavor, name, flags, sizeof(type))) = (initValue)
  242.  
  243. extern Pntr    addIVar();
  244.  
  245.  
  246. /*
  247. Pntr
  248. AddClassVar(flavor, name, flags, type, initValue)
  249.     Pntr    flavor;
  250.     char    *name;
  251.     int     flags;
  252.     ....    type, initValue;
  253.  
  254.     AddClassVar() is used to add class variables to a Flavor before the
  255.     flavor is compiled.  The arguments are the same as those in
  256.     AddClassVar().  This is a nonstandard extension of flavors found only
  257.     in CFlavors.
  258. */
  259. #define AddClassVar(flavor, name, flags, type, initValue) \
  260.   *((type*)addCVar(flavor, name, flags, sizeof(type))) = (initValue)
  261.  
  262. extern Pntr    addCVar();
  263.  
  264.  
  265. /*
  266. void
  267. CompileFlavor(flavor)
  268.     Pntr    flavor;
  269.  
  270.     CompileFlavor() sets up the flavor so that it can be used by other
  271.     flavors.  All methods, variables, required items, etc. should be complete
  272.     before calling this function.  In addition instance can not be made of
  273.     flavors that have not been compiled.  The argument must be a pointer to
  274.     a flavor or a flavor name.
  275. */
  276. extern void CompileFlavor();
  277.  
  278.  
  279. /*
  280. Pntr
  281. ContinueWhopper(methods, object, the_rest)
  282.     Pntr        methods;
  283.     Instance*   *object;
  284.     ....        the_rest;
  285.  
  286. */
  287. extern Pntr  ContinueWhopper();
  288.  
  289.  
  290. /*
  291. Flavor*
  292. StringToFlavor(name)
  293.     char    *name;
  294.  
  295.     StringToFlavor() will return a pointer to the Flavor which has the same
  296.     name as the argument 'name'.
  297. */
  298. extern Flavor*  StringToFlavor();
  299.  
  300.  
  301. /*
  302. char*
  303. FlavorToString(flavor)
  304.     Flavor  *flavor;
  305.  
  306. */
  307. extern char*    FlavorToString();
  308.  
  309.  
  310. /*
  311. Instance*
  312. MakeInstance(flavor, init)
  313.     Flavor  *flavor;
  314.     int        init;
  315.  
  316.     MakeInstance() is used to make instances of a flavor.  It's first
  317.     argument must be a pointer to a flavor or a flavor name.  MakeInstance()
  318.     returns a pointer to an instance of the flavor.
  319. */
  320. extern Instance*    MakeInstance();
  321.  
  322.  
  323. /*
  324. Pntr
  325. Send(object, message, the_rest)
  326.     Instance    *object;
  327.     char        *message;
  328.     ....        the_rest;
  329.  
  330.     Send() is used to send messages to instances of a Flavor.  The first
  331.     argument must be an instance of a flavor.  The second is a string for
  332.     the method to be invoked.  The last set argument (or arguments),
  333.     the_rest_of_the_arguments can be any number of additional arguments that
  334.     should be applied to the method function.  The method functions must
  335.     always have self (or the instance) as it's first argument.  The limit
  336.     on additional arguments is that they be one less than the compiler limit
  337.     and that the total space they take up should be less that the space
  338.     required by ten double. (usually this is 80 bytes)  If the compiler
  339.     supports structures as arguments that will work as well.
  340. */
  341. extern Pntr     Send();
  342.  
  343.  
  344. /*
  345. Pntr
  346. BroadCast(flavor, message, the_rest)
  347.     Flavor      *flavor;
  348.     char        *message;
  349.     ....        the_rest;
  350.  
  351.     BroadCast() is similar to Send except the message is sent to every
  352.     instance of the flavor specified.  This is a nonstandard extension of
  353.     flavors found only in CFlavors.
  354. */
  355. extern Pntr     BroadCast();
  356.  
  357.  
  358. /*
  359. Pntr
  360. GetVar(object, varName)
  361.     Instance    *object;
  362.     char        *varName;
  363.  
  364.     GetVar() is used to return a pointer to the variable `name' for the
  365.     instance specified.  The returned pointer is for a (char) type and should
  366.     be cast to the actual variable type before it is used.  The function does
  367.     not invoke any before or after daemons.
  368. */
  369. extern Pntr     GetVar();
  370.  
  371.